﻿<?php require_once('../Connections/conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rscolsubcat = 10;
$pageNum_rscolsubcat = 0;
if (isset($_GET['pageNum_rscolsubcat'])) {
  $pageNum_rscolsubcat = $_GET['pageNum_rscolsubcat'];
}
$startRow_rscolsubcat = $pageNum_rscolsubcat * $maxRows_rscolsubcat;

mysql_select_db($database_conexao, $conexao);
$query_rscolsubcat = "SELECT s.id_subcategoria,c.categoria, s.Subcategoria FROM subcategorias AS s INNER JOIN categorias AS c ON s.id_categoria = c.id_categoria ORDER BY id_subcategoria";
$query_limit_rscolsubcat = sprintf("%s LIMIT %d, %d", $query_rscolsubcat, $startRow_rscolsubcat, $maxRows_rscolsubcat);
$rscolsubcat = mysql_query($query_limit_rscolsubcat, $conexao) or die(mysql_error());
$row_rscolsubcat = mysql_fetch_assoc($rscolsubcat);

if (isset($_GET['totalRows_rscolsubcat'])) {
  $totalRows_rscolsubcat = $_GET['totalRows_rscolsubcat'];
} else {
  $all_rscolsubcat = mysql_query($query_rscolsubcat);
  $totalRows_rscolsubcat = mysql_num_rows($all_rscolsubcat);
}
$totalPages_rscolsubcat = ceil($totalRows_rscolsubcat/$maxRows_rscolsubcat)-1;

$queryString_rscolsubcat = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rscolsubcat") == false && 
        stristr($param, "totalRows_rscolsubcat") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rscolsubcat = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rscolsubcat = sprintf("&totalRows_rscolsubcat=%d%s", $totalRows_rscolsubcat, $queryString_rscolsubcat);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Documento sem título</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>

<body>
<table width="960" align="center">
  <tr>
    <td colspan="2">
	<?php include ("../temadmin/cabecalho.php");?>

</td>
  </tr>
  <tr>
    <td colspan="2">
	<?php include "../temadmin/menu_vertical.php";
	?>
    </td>
  </tr>
  <tr>
    <td width="250">
	<?php include "../temadmin/menu.php";?>
    </td>
    <td width="698">
   		<table width="99%" align="center">
  <tr>
    <td width="951" height="21" align="center"><strong>Subcategorias
	

    </strong></td>
  </tr>
  <tr>
    <td>   
    <table width="99%">
        <tr>
          <td>&nbsp;</td>
          <td colspan="3">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td colspan="3" align="center"><strong>Lista Subcategoria</strong></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td colspan="3"><table width="99%" height="126" border="1" align="center">
            <tr bgcolor="#999999">
              <th align="left" scope="col">id</th>
              <th align="left" scope="col">Subcategoria</th>
              <th align="left" scope="col">Categoria</th>
              <th colspan="2" scope="col">Açao</th>
              </tr>
            <?php do { ?>
            <tr bgcolor="#CCCCCC">
              <td height="26"><?php echo $row_rscolsubcat['id_subcategoria']; ?></td>
              <td><?php echo $row_rscolsubcat['Subcategoria']; ?></td>
              <td><?php echo $row_rscolsubcat['categoria']; ?></td>
              <td width="5%"><a href="index.php?link=3&amp;acao=editar&amp;idsubcategoria=<?php echo $row_rscolsubcat['id_subcategoria']; ?>"><img src="img/Editar.png" width="16" height="16" /></a></td>
              <td width="6%"><a href="index.php?link=3&amp;acao=excluir&amp;idsubcategoria=<?php echo $row_rscolsubcat['id_subcategoria']; ?>"><img src="img/Excluir.png" width="16" height="16" /></a></td>
              </tr>
            <?php } while ($row_rscolsubcat = mysql_fetch_assoc($rscolsubcat)); ?>
            <tr bgcolor="#999999">
              <td height="25" colspan="5" align="right"><a href="index.php?link=3&amp;acao=inserir"><img src="img/inserir.png" width="69" height="15" /></a></td>
              </tr>
            <tr>
              <td height="4" colspan="5"><table border="0">
                <tr>
                  <td><?php if ($pageNum_rscolsubcat > 0) { // Show if not first page ?>
                    <a href="<?php printf("%s?pageNum_rscolsubcat=%d%s", $currentPage, 0, $queryString_rscolsubcat); ?>"><img src="img/First.gif" /></a>
                    <?php } // Show if not first page ?></td>
                  <td><?php if ($pageNum_rscolsubcat > 0) { // Show if not first page ?>
                    <a href="<?php printf("%s?pageNum_rscolsubcat=%d%s", $currentPage, max(0, $pageNum_rscolsubcat - 1), $queryString_rscolsubcat); ?>"><img src="img/Previous.gif" /></a>
                    <?php } // Show if not first page ?></td>
                  <td><?php if ($pageNum_rscolsubcat < $totalPages_rscolsubcat) { // Show if not last page ?>
                    <a href="<?php printf("%s?pageNum_rscolsubcat=%d%s", $currentPage, min($totalPages_rscolsubcat, $pageNum_rscolsubcat + 1), $queryString_rscolsubcat); ?>"><img src="img/Next.gif" /></a>
                    <?php } // Show if not last page ?></td>
                  <td><?php if ($pageNum_rscolsubcat < $totalPages_rscolsubcat) { // Show if not last page ?>
                    <a href="<?php printf("%s?pageNum_rscolsubcat=%d%s", $currentPage, $totalPages_rscolsubcat, $queryString_rscolsubcat); ?>"><img src="img/Last.gif" /></a>
                    <?php } // Show if not last page ?></td>
                  </tr>
                </table></td>
              </tr>
          </table></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;
          </td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        </table>
   </td>
  </tr>
</table>
    </td>
  </tr>
  <tr>
    <td colspan="2">
	<?php include ("../temadmin/rodape.php");?>
    </td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($rscolsubcat);

?>
